var Pms = {

    /**
     * 获取当前设备类型
     */
    getDevices: function () {
        var sUserAgent = navigator.userAgent.toLowerCase(),
            bIsIpad = sUserAgent.match(/ipad/i) == "ipad",
            bIsPad = sUserAgent.match(/pad/i) == "pad",
            bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os",
            bIsMidp = sUserAgent.match(/midp/i) == "midp",
            bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4",
            bIsUc = sUserAgent.match(/ucweb/i) == "ucweb",
            bIsAndroid = sUserAgent.match(/android/i) == "android",
            bIsCE = sUserAgent.match(/windows ce/i) == "windows ce",
            bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
        if (bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
            return "mobile";
        } else if (bIsIpad || bIsPad) {
            return "pad";
        } else {
            return "pc"
        }
    },
    /**
     * 获取指定的URL参数值
     * @param {String} paramName 
     */
    getParameter: function (paramName) {
        var paramValue = "", isFound = !1;
        if (window.location.search.indexOf("?") == 0 && window.location.search.indexOf("=") > 1) {
            var arrSource = unescape(window.location.search).substring(1, window.location.search.length).split("&"), i = 0;
            while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
        }
        return paramValue == "" && (paramValue = undefined), paramValue
    },
    /*设置cookie*/
    setCookie: function (name, value, iDay) {
        var oDate = new Date();
        oDate.setDate(oDate.getDate() + iDay);
        document.cookie = name + '=' + value + ';expires=' + oDate;
    },
    /*使用方法：setCookie('user', 'simon', 11);*/
    /*获取cookie*/
    getCookie: function (name) {
        var arr = document.cookie.split('; '); //多个cookie值是以; 分隔的，用split把cookie分割开并赋值给数组
        for (var i = 0; i < arr[i].length; i++) //历遍数组
        {
            var arr2 = arr[i].split('='); //原来割好的数组是：user=simon，再用split('=')分割成：user simon 这样可以通过arr2[0] arr2[1]来分别获取user和simon 
            if (arr2[0] == name) //如果数组的属性名等于传进来的name
            {
                return arr2[1]; //就返回属性名对应的值
            }
            return ''; //没找到就返回空
        }
    },
    /*使用方法：getCookie('user')*/
    /*删除cookie*/
    removeCookie: function (name) {
        Pms.setCookie(name, 1, -1); //-1就是告诉系统已经过期，系统就会立刻去删除cookie
    },
    /**
     * 获取指定的sessionId参数值
     */
    clearToken: function () {
        localStorage.removeItem("token");
    },
    getToken: function () {
        var token = "";
        if (localStorage["token"] != undefined) {
            token = localStorage["token"];
        }
        return token;
    },
    setToken: function (token) {
        localStorage["token"] = token;
    },
    /**
     * 是否在登录页面
     */
    isLoginPage: function () {
        return location.pathname.indexOf("login") == -1;
    },
    /**
     * 获取localStorage数据
     * @param {*} key localStorage中的key string
     * @param {*} type 如果localStorage为空，type是默认值 如{}
     * @returns localStorage数据 arr
     */
    getDate: function (key, type) {
        var str = localStorage.getItem(key)
        return str ? JSON.parse(str) : type

    },
    setDate: function (key, data) {
        localStorage[key] = JSON.stringify(data)
    },
    getSessData: function (key, type) {
        var str = sessionStorage.getItem(key)
        return str ? JSON.parse(str) : type
    },
    setSessData: function (key, data) {
        sessionStorage[key] = JSON.stringify(data)
    },
    /**
    * 清空本地所有LocalStorage
    */
    emptyAllLocalStorage() {
        for (const key in localStorage) {
            localStorage.removeItem(key)
        }
    },
    /**
    * 清空本地所有LocalStorage
    */
    emptyAllsessionStorage() {
        for (const key in sessionStorage) {
            sessionStorage.removeItem(key)
        }
    },
};
window.Pms = Pms;